package com.ethan.minimalist.mvp.presenter

import com.cxz.kotlin.baselibs.ext.startHttp
import com.cxz.kotlin.baselibs.mvp.BasePresenter
import com.ethan.minimalist.mvp.contract.IUpdateUserContract
import com.ethan.minimalist.mvp.model.UpdateUserModel
import com.ethan.minimalist.utils.Md5Utils

/**
 * @author admin
 * @date 2018/11/20
 * @desc
 */
class UpdateUserPresenter : BasePresenter<IUpdateUserContract.Model, IUpdateUserContract.View>(), IUpdateUserContract.Presenter {

    override fun createModel(): IUpdateUserContract.Model? = UpdateUserModel()


    override fun update(username: String, password: String) {
        val pwd = Md5Utils.digest(password)
        mModel?.update(username, pwd)?.startHttp(mModel, mView, onSuccess = {
            mView?.updateUserSuc()
        })
    }


    override fun logout() {
        mModel?.logout()?.startHttp(mModel, mView, onSuccess = {
            mView?.logoutSuccess()
        })
    }

}